package com.woniuxy.listener;

import com.rabbitmq.client.Channel;
import com.woniuxy.po.TopicMail;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: 马宇航
 * @Do: 延迟队列消息监听器
 * @DateTime: 22/07/07/0007 下午 2:57
 * @Component: 成都蜗牛学苑
 **/
@Component
@RabbitListener(queues = "delayQueue")
public class DelayListener {
    @RabbitHandler
    public void handle(TopicMail topicMail, Channel channel, Message message){
        System.out.println("延迟消息接收成功："+topicMail);
        //手动确认消息接收成功
        try {
            channel.basicQos(1);
            System.out.println("消息头："+message.getMessageProperties());
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
